/*    */ package com.zimbra.cs.dav.service.method;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.cs.dav.DavContext;
/*    */ import com.zimbra.cs.dav.DavElements;
/*    */ import com.zimbra.cs.dav.DavException;
/*    */ import com.zimbra.cs.dav.caldav.Range.TimeRange;
/*    */ import com.zimbra.cs.dav.resource.CalendarCollection;
/*    */ import com.zimbra.cs.dav.resource.DavResource;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.ServletOutputStream;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.dom4j.Document;
/*    */ import org.dom4j.Element;
/*    */ import org.dom4j.QName;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class FreeBusyQuery
/*    */   extends Report
/*    */ {
/*    */   public void handle(DavContext ctxt)
/*    */     throws DavException, IOException, ServiceException
/*    */   {
/* 42 */     Element query = ctxt.getRequestMessage().getRootElement();
/* 43 */     if (!query.getQName().equals(DavElements.E_FREE_BUSY_QUERY)) {
/* 44 */       throw new DavException("msg " + query.getName() + " is not free-busy-query", 400, null);
/*    */     }
/* 46 */     Element trElem = query.element(DavElements.E_TIME_RANGE);
/* 47 */     if (trElem == null) {
/* 48 */       throw new DavException("need time-range", 400, null);
/*    */     }
/* 50 */     Range.TimeRange timeRange = new Range.TimeRange(trElem);
/* 51 */     DavResource rs = ctxt.getRequestedResource();
/*    */     
/* 53 */     if (!(rs instanceof CalendarCollection)) {
/* 54 */       throw new DavException("not a calendar collection", 400, null);
/*    */     }
/*    */     try {
/* 57 */       String freebusy = ((CalendarCollection)rs).getFreeBusyReport(ctxt, timeRange);
/* 58 */       HttpServletResponse resp = ctxt.getResponse();
/* 59 */       resp.setContentType("text/calendar");
/* 60 */       resp.getOutputStream().write(freebusy.getBytes("UTF-8"));
/* 61 */       ctxt.responseSent();
/*    */     } catch (ServiceException se) {
/* 63 */       throw new DavException("can't get freebusy report", 500, se);
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/service/method/FreeBusyQuery.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */